﻿using AutoMapper.Configuration;
using Common.Dtos;
using Newtonsoft.Json;
using Sigma.Admin.API.Context.Entity;

namespace Sigma.Admin.API.Extensions
{
    public class AutoMapperProFile : MapperConfigurationExpression
    {
        public AutoMapperProFile()
        {
            CreateMap<UserEntity, UsersDto>().ReverseMap();
            CreateMap<UserEntity, UsersDto>()
.ForMember(dest => dest.PermissionKey, opt => opt.MapFrom(src => JsonConvert.DeserializeObject<List<int>>(src.PermissionKey)?? new List<int>()));
            CreateMap<RoleEntity, RolesDto>().ReverseMap();
            CreateMap<MenuEntity, MenuDto>().ReverseMap();
            CreateMap<PermissionEntity, PermissionDto>().ReverseMap();
        }
    }
}
